package com.orangelife.mobile.housepurchasing.biz;

import com.curry.android.http.VolleyHttpUtil;
import com.curry.android.util.JSONHelper;
import com.orangelife.mobile.constants.Constant;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 从服务器获取房源列表
 * Created by HeYuCan on 2016/5/19.
 */
public class HouseListHttpBiz {
    /** 房屋销售类型列表 */
    private static final String URL_SALETYPE_LIST = Constant.URL_SALE_TYPE;
    /** 房源列表 */
    private static final String URL_CIRCUMTESO_HOUSE_LIST = Constant.URL_REALESTATE_LIST;

    /** 获取城市列表*/
    private static final String URL_CITY_LIST=Constant.PATH_SELECT_CITY;

   




    public static int getDataTotal(JSONObject response) {
        int total = 0;
        try {
            if (response != null) {
                String strTotal = response.getString("total");
                if (strTotal != null) {
                    try {
                        total = Integer.parseInt(strTotal);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return total;
    }





    /**加载左侧销售类型*/
    public static void requestSaleTypeList(String commID,VolleyHttpUtil.ResponseCallBack callback) {

        HashMap<String, String> map = new HashMap<>();
        map.put("commID",commID);
        VolleyHttpUtil.getInstance().getWithCallback(URL_SALETYPE_LIST, map, callback);
    }

/**加载右侧房源列表*/
    public static void requestHouseList(String saleTypeID,String commID,VolleyHttpUtil.ResponseCallBack callback) {

        HashMap<String, String> map = new HashMap<>();

        map.put("commID", commID);
        map.put("saleType", saleTypeID);
        VolleyHttpUtil.getInstance().getWithCallback(URL_CIRCUMTESO_HOUSE_LIST,map,callback);
    }

    /**点击选择城市,加载城市列表*/
    public static void requestCityList(VolleyHttpUtil.ResponseCallBack callback) {

        VolleyHttpUtil.getInstance().getWithCallback(URL_CITY_LIST,null,callback);
    }

    public static List<Map<String, Object>> getCityList(Object response) {
        Map<String, Object> map = JSONHelper.jsonToMap(String.valueOf(response));
        List<Map<String,Object>> list=(List<Map<String,Object>>)map.get("pageEntity");
        return list;
    }


    public static List<Map<String, Object>> getLeftListRight(Object response) {
        Map<String, Object> map = JSONHelper.jsonToMap(String.valueOf(response));
        List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("pageEntity");
        return list;
    }

    public static List<Map<String, Object>> getHouseListRight(Object response) {
        Map<String, Object> map = JSONHelper.jsonToMap(String.valueOf(response));
            List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("pageEntity");
            return list;
    }

    public static String  saleTypeCn(String id){
        String saleName="";
        switch (id){
            case "1":
                saleName="出售";
                break;
            case "2":
                saleName="出租";
                break;
            case "3":
                saleName="二手房";
                break;
            case "4":
                saleName="停车位";
                break;
            case "5":
                saleName="租商铺";
                break;
            case "6":
                saleName="卖商铺";
                break;
        }
        return saleName;
    }

    /**
     *
     * @param id
     * @return 0是总价 1是单价
     */
    public static int saleType(String id){
        int sale=0;
        switch (id){
            case "1":
                sale= 0;
                break;
            case "2":
                sale= 1;
                break;
            case "3":
                sale=0;
                break;
            case "4":
                sale=0;
                break;
            case "5":
                sale=1;
                break;
            case "6":
                sale=0;
                break;
        }
        return sale;
    }
}

